package practice;
import java.util.Scanner;
import java.util.Random;
public class Day07_1 {
    public static void main(String[] args) {
        Scanner input1 = new Scanner(System.in);
        Random rand1 = new Random();

        //第一题  猜数字
//        int number1 = rand1.nextInt(1001);
//        while (true) {
//            System.out.print("(1-1000)猜吧：");
//            int guess1 = input1.nextInt();
//            if (guess1>number1) {
//                System.out.println("猜大了，继续猜!");
//            } else if (guess1<number1) {
//                System.out.println("猜小了，继续猜！");
//            } else {
//                System.out.println("猜对了！");
//                break;
//            }
//        }

        //第二题  生成验证码
//        System.out.print("要生成几位数的验证码：");
//        int number1 = input1.nextInt();
//        String code1 = generateCode1(number1);
//        System.out.println(code1);

        //第三题  素数 列出2-100以内的素数
//        for (int num=2;num<=100;num++) {
//            boolean flag = true;
//            for (int i=2;i<=num/2;i++) {
//                if (num%i==0) {
//                    flag = false;
//                    break;
//                }
//            }
//            if (flag) {
//                System.out.println(num+"是素数。");
//            }
//        }

        //第四题 计算机票折后价格
//        while (true) {
//            System.out.print("请输入机票原价：");
//            double price1 = input1.nextDouble();
//            System.out.print("请输入月份：");
//            int month1 = input1.nextInt();
//            System.out.print("头等舱请按1；商务舱请按2；经济舱请按3：");
//            int seat1 = input1.nextInt();
//            boolean judgement1 = rightWrong(month1, seat1);
//            if (judgement1 == false) {
//                continue;
//            }
//            double finalPrice = getPrice (month1,seat1,price1);
//            System.out.println("机票最终价格为："+finalPrice);
//            System.out.println("输入1重新计算，输入其他任意键结束！");
//            int number1 = input1.nextInt();
//            if (number1==1) {
//            } else {
//                break;
//            }
//        }

        //第五题 计算总分和平均分
//        System.out.print("要计算几位评委的分数：");
//        int number1 = input1.nextInt();
//        double[] point1 = point1(number1);
//        travel1(point1);
//        System.out.println();
//        double sum1 = sum1(point1);
//        System.out.println("去掉最大值最小值后的评委总分为："+sum1);
//        double ave1 = average1(point1);
//        System.out.println("平均分为："+ave1);



    }
    //第二题  生成验证码方法
    public static String generateCode1(int m) {
        String code1 = "";
        char[] codeBank = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
                'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
                'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
                'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
                'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7',
                '8', '9'};
        Random rand1 = new Random();
        for (int i = 1; i <= m; i++) {
            int index1 = rand1.nextInt(codeBank.length);
            code1 += codeBank[index1];
        }
        return code1;
    }

    //第四题
    //判断输入信息是否错误。
    public static boolean rightWrong(int month, int seat) {
        if (month > 12 || month < 1) {
            System.out.println("输入错误。");
            return false;
        }
        if (seat < 1 || seat > 3) {
            System.out.println("输入错误。");
            return false;
        }
        return true;

    }

    //计算机票价格
    public static double getPrice(int month, int seat, double price) {
        if (month >= 5 && month <= 10) {
            switch (seat) {
                case 1:
                    price *= 0.9;
                    break;
                case 2:
                    price *= 0.85;
                    break;
                case 3:
                    price *= 0.8;
            }
        } else {
            switch (seat) {
                case 1:
                    price *= 0.7;
                    break;
                case 2:
                    price *= 0.65;
                    break;
                case 3:
                    price *= 0.6;
            }
        }
        return price;
    }

    //第五题
    //输入评委分数
    public static double[] point1 (int number1) {
        Scanner input1 = new Scanner(System.in);
        double[] point1 = new double[number1];
        for (int i=0;i<number1;i++) {
            System.out.print("第"+(i+1)+"位评委的分数为：");
            point1[i] = input1.nextInt();
        }
        return point1;
    }
    //遍历评委分数
    public static void travel1 (double[] a) {
        for (int i=0;i<a.length;i++) {
            System.out.print(a[i]+"\t");
        }
    }
    //计算评委总分
    public static double sum1 (double[] a) {
        double max1 = a[0];
        double min1 = a[0];
        double sum1 = 0;
        for (int i=0;i<a.length;i++) {
            if (a[i]>max1) {
                max1 = a[i];
            }
            if (a[i]<min1) {
                min1 = a[i];
            }
            sum1 += a[i];
        }
        double sum2 = sum1 - max1 - min1;
        return sum2;
    }
    //求平均分
    public static double average1 (double[] a) {
        double sum1 = sum1(a);
        double ave1 = sum1/(a.length-2);
        return ave1;
    }

}